/**
 *  函数节流
 * @param {*} _fn
 * @param {*} _delay
 * @returns
 */
export const throttle = (_fn, _delay = 3000) => {
  let startTime = 0;
  return function (...agrs) {
    let endTime = Date.now();
    if (endTime - startTime > _delay) {
      startTime = endTime;
      _fn.apply(this, agrs);
    }
  };
};

// js 数字每个三位加一个逗号


// export function convert(num){
//   var str = num.toString();
//   var reg = str.indexOf(".") > -1 ? /(\d)(?=(\d{3})+\.)/g : /(\d)(?=(?:\d{3})+$)/g;
//   return str.replace(reg,"$1,");
// }

export function outputcents(amount) {
  amount = Math.round(((amount) - Math.floor(amount)) * 100);
  return (amount < 10 ? '.0' + amount : '.' + amount);
}

export function convert(str) {
  var newStr = "";
  var count = 0;
  // 当数字是整数
  if (str.indexOf(".") == -1) {
      for (var i = str.length - 1; i >= 0; i--) {
          if (count % 3 == 0 && count != 0) {
              newStr = str.charAt(i) + "," + newStr;
          } else {
              newStr = str.charAt(i) + newStr;
          }
          count++;
      }
      str = newStr ; //自动补小数点后两位
      return str;
  }
  // 当数字带有小数
  else {
      for (var i = str.indexOf(".") - 1; i >= 0; i--) {
          if (count % 3 == 0 && count != 0) {
              newStr = str.charAt(i) + "," + newStr;
          } else {
              newStr = str.charAt(i) + newStr; //逐个字符相接起来
          }
          count++;
      }
      str = newStr + (str + "00").substr((str + "00").indexOf("."), 3);
      return str;
  }
}





